<template>
    <div class="header">
        <div class="time">2025-09-05 09:49:44 星期五</div>
        <div class="info">
            <p class="home" @click="open">网站首页</p>
            <div class="logout"
                 @click="logout">
                <el-icon class="icon">
                    <UserFilled />
                </el-icon>
                <p>admin</p>
                <el-icon class="icon">
                    <SwitchButton />
                </el-icon>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router';
const router = useRouter()
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
const user_url = localStorage.getItem('user_url')

const logout = () =>{
    ElMessageBox.confirm(
        '此操作将注销登录, 是否继续?',
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        localStorage.clear()
        router.replace('/login')
    }).catch(() => {
        // 统一处理异常
    });
}

const open = () => {
    window.open(user_url)
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.header {
    width: 100%;
    height: 50px;
    padding: 0 20px;
    position: relative;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
    .time {
    }
    .info {
        display: flex;
        align-items: center;
        .home {
            margin-right: 20px;
            cursor: pointer;
        }
        .logout {
            display: flex;
            align-items: center;
            cursor: pointer;
            p {
                margin: 0 10px;
            }
        }
    }
}
</style>